#ifndef MUSICANIMATIONSTACKEDWIDGET_H
#define MUSICANIMATIONSTACKEDWIDGET_H

#include <QPainter>
#include <QStackedWidget>
#include <QPropertyAnimation>

class AnimationStackedWidget : public QStackedWidget
{
    Q_OBJECT
public:
    enum AnimationType
    {
        TopToBottom,    ///Animation from top to bottom
        BottomToTop,    ///Animation from bottom to top
        LeftToRight,    ///Animation from left to right
        RightToLeft     ///Animation from right to left
    };

    explicit AnimationStackedWidget(QWidget *parent = 0);
    virtual ~AnimationStackedWidget();

    /// Get class object name.
    static QString getClassName();

    /// Start to anmiation by index.
    void start(int index);

    /// Set previoud and current index.
    void setIndex(int previous, int current);

    /// Set animation start and end pos distance and animation type.
    void setLength(int length, AnimationType type);

    /// Set animation duration.
    void setDuration(int duration);
    /// Get animation duration.
    int getDuration() const;

private slots:
    /// Animation value changed.
    void valueChanged(const QVariant &value);
    /// Animation finished.
    void animationFinished();

protected:
    /// Override the widget event.
    virtual void paintEvent(QPaintEvent *event) override;

    /// Render previous widget.
    void renderPreviousWidget(QPainter &painter, QTransform &transform);

    /// Render current widget.
    void renderCurrentWidget(QPainter &painter, QTransform &transform);

private:
    bool m_isAnimating;
    float m_currentValue;
    int m_currentIndex, m_previousIndex;
    AnimationType m_type;
    QPropertyAnimation *m_animation;
};

#endif // MUSICANIMATIONSTACKEDWIDGET_H
